﻿
using IBll;
using IDal;
using MD5Hash;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bll
{
    /// <summary>
    /// 继承管理员接口
    /// </summary>
    public class UserMagerbLL : IUserMagerbLL
    {
         public UserMagerbLL(IStateDal<UserMager> stateD)
        {
            StateD = stateD;
        }

        public IStateDal<UserMager> StateD { get; }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="name">用户名</param>
        /// <param name="pwd">密码</param>
        /// <returns>通过用户名密码登录</returns>
        public UserMager Loing(string name, string pwd)
        {
            try//异常处理
            {
                ///查询用户名
                var emp = StateD.GetValues().FirstOrDefault(x => x.UserMagerName == name);
                if (emp == null)
                {
                    emp = new UserMager { UserMagerId = -1 };
                }else
                {
                    emp.UserMagerPwd = emp.UserMagerPwd.GetMD5();
                    if (emp.UserMagerPwd!=pwd.GetMD5())
                    {
                        emp = new UserMager { UserMagerId = -2 };
                    }
                }
                 return emp;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
